package com.collectplus.express.menu;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.collectplus.express.R;
import com.collectplus.express.model.OrderRouterBean;

import droid.frame.activity.base.BaseAdapterExt;

/**
 * 订单详情
 * 
 * @author coffee<br>
 *         2015-11-16下午4:17:52
 */
public class OrderDetailAdapter extends BaseAdapterExt<OrderRouterBean> {

	private SimpleDateFormat sdf;

	public OrderDetailAdapter(Activity context, ArrayList<OrderRouterBean> items) {
		super(items, context);
		sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.order_detail_item, parent, false);
			viewHolder.mStatus = (TextView) convertView.findViewById(R.id.order_detail_desc);
			viewHolder.mTime = (TextView) convertView.findViewById(R.id.order_detail_time);
			viewHolder.mImg = (ImageView) convertView.findViewById(R.id.order_detail_img);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		OrderRouterBean item = getItem(position);
		viewHolder.mStatus.setText(item.getDescription());
		viewHolder.mTime.setText(sdf.format(new Date(item.getUpdateTime())));

		if (position == 0) {
			// if (mArr.get(position).getStatusId().equals("3")) {
			// viewHolder.mImg.setImageResource(R.drawable.ic_wuliu2);
			// } else
			viewHolder.mImg.setImageResource(R.drawable.parcel_route_1);
		} else {
			viewHolder.mImg.setImageResource(R.drawable.parcel_route_2);
		}

		// if (mArr.size() == 1) {
		// viewHolder.mImg.setImageResource(R.drawable.timeline1_1);
		// } else {
		// if (position == 0) {
		// viewHolder.mImg.setImageResource(R.drawable.timeline1);
		// } else if (position == getCount() - 1) {
		// // if (mArr.get(position).getStatusId().equals("3")) {
		// viewHolder.mImg.setImageResource(R.drawable.timeline3);
		// // } else
		// // viewHolder.mImg.setImageResource(R.drawable.timeline2_2);
		// } else {
		// viewHolder.mImg.setImageResource(R.drawable.timeline2);
		// }
		// }
		return convertView;
	}

	private class ViewHolder {
		private TextView mStatus;// 状态
		private TextView mTime;// 时间
		private ImageView mImg;// 图片
	}

}
